#!/usr/bin/env python
#-*- coding: utf-8 -*-
from django.db import models

# Create your models here.
'''
class UserInfo(models.Model):
    username =  models.CharField(max_length=50)
    userphome = models.CharField(max_length=50)
    useremail = models.EmailField(max_length=50)
    userpassword = models.CharField(max_length=50)
    user_create_date = models.DateField(auto_now_add=True)
    user_update_date = models.DateField(auto_now=True)
    group_relation = models.ManyToManyField('GroupInfo')
class GroupInfo(models.Model):
    groupname = models.CharField(max_length=50)
    group_create_date = models.DateField(auto_now_add=True)
    group_update_date = models.DateField(auto_now=True)
class HostLists(models.Model):
    hostname = models.CharField(max_length=50)
    host_ip = models.ForeignKey(UserInfo,verbose_name=u'所属用户')
    host_system = models.CharField(max_length=50)
    host_cpu_userd = models.CharField(max_length=50)
    host_mem_total = models.IntegerField()
    host_disk_remain = models.IntegerField()
    create_date = models.DateField(auto_now_add=True)
    update_date = models.DateField(auto_now=True)
'''
class UserType(models.Model):
    name = models.CharField(max_length=50)
class UserInfo(models.Model):
    username = models.CharField(max_length=50)
    password = models.CharField(max_length=50)
    email = models.EmailField()
    user_type = models.ForeignKey('UserType') # 外键需要单独建一个字段，与UserType是一对多的关系。
class UserGroup(models.Model):
    GroupName = models.CharField(max_length=50)
    user = models.ManyToManyField('UserInfo')   # 组与用户之间是多对多关系，会额外生成一张两者关系表
class Asset(models.Model): # 主机信息表
    hostname = models.CharField(max_length=256)
    ip = models.GenericIPAddressField()
    user_group = models.ForeignKey(UserGroup) # 主机属于哪些组，单引号加不加都行，值是UserGroup类的一个对象

    def __unicode__(self):  # 对Asset的对象进行定制输出显示
        temp = '当前Asset对象中包含%s,%s' %(self.hostname,self.ip)
        return temp

